<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta charset="UTF-8" />
<meta
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"
	name="viewport" />
<title>健康数据</title>
<script type="text/javascript">
	//获取XmlHttpRequest对象
	function createXmlHttpRequest() {
		if (window.ActiveXObject) {
			return new ActiveXObject("Microsoft.XMLHTTP");
		} else if (window.XMLHttpRequest) {
			return new XMLHttpRequest();
		}
	}

	//获取url后的参数值
	function GetRequest() {
		   var url = location.search; //获取url中"?"符后的字串
		   var theRequest = new Object();
		  
		   if (url.indexOf("?") != -1) {
		      var str = url.substr(1);
		      strs = str.split("&");
		      for(var i = 0; i < strs.length; i ++) {
		         theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
		      }
		      
		   }
		   return theRequest;
	}

	//获取url路径#后的参数值
	function GetParam(){
		
		var Url=top.window.location.href;
		var u='',g='';
		if(Url.indexOf("#")){
			u=Url.split("#");
		}else if(Url.indexOf("?")){
			u=Url.split("?");
		}
		if (u.length==1){
			g='';
		}else{
			g=u[1]; 
		}
		
		   return g;
	}
	//获取项目名
	var pathName=window.document.location.pathname;
	var ctx=pathName.substring(0,pathName.substr(1).indexOf('/')+1);

	function GetUrl(){
		 var pathName=window.document.location.pathname;
		 var projectName=pathName.substring(pathName.substr(1).indexOf('/')+1);
		var url="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx31cf436485b2fdf8&redirect_uri=http%3a%2f%2f203.195.189.85%2flifesense-healthcenter%2fwechat%2fauthx4HTML%3ft%3d"+projectName+"&response_type=code&scope=snsapi_base&state=gh_4bc17495d97a#wechat_redirect";

		return url;
	}

	//
	function GetRequestValue(){
//		var param=new Object();
//		param = GetRequest();
		
		var xhr = createXmlHttpRequest();
		xhr.onreadystatechange = function() {
			if (xhr.readyState == 4) {
				if (xhr.status == 200) {
					var json = xhr.responseText;
						jsonData = eval( "(" + json + ")" );//转换后的JSON对象
						if(jsonData.accountId != null){
							GetMemberId(jsonData.accountId);
						}
				}
			}
		};
		var url = ctx+"/wechat/ajax_webAuthorize";
//		xhr.open("post", url + "?code=" + param["code"] +"&&state="+param["state"]+"&&scope="+param["scope"]+"&&mathNum="+Math.random(), true);
		xhr.open("post", url+"?num=1", true);
		xhr.send();
	}

	function GetMemberId(accountId){
		var xhr = createXmlHttpRequest();
		xhr.onreadystatechange = function() {
			if (xhr.readyState == 4) {
				if (xhr.status == 200) {
					var json = xhr.responseText;
					document.getElementById("memberId").value=json;
					//初始化数据	
					ajaxLoadData();
				}
			}
		};
		var url = ctx+"/wechat/ajax_openId";
		xhr.open("post", url + "?accountId="+accountId+"&&mathNum="+Math.random(), true);
		xhr.send();
	}

	//显示块
	function showDOM(id){
		var dom = document.getElementById(id);
		dom && (dom.style.display = 'block');
	}
	//隐藏块
	function hiddenDOM(id){
		var dom = document.getElementById(id);
		dom && (dom.style.display = 'none');
	}
	</script>

<style>
* {
	padding: 0;
	margin: 0;
	font-family: Helvetica;
}

.top {
	color: #3E3D3E;
	position: relative;
	overflow: hidden;
	width: 100%;
	height: 196px;
}

.line {
	height: 48px;
	width: 100%;
	border-bottom: solid 1px #DCDCDD;
	position: absolute;
	z-index: 888;
}

.menu0 {
	top: 0;

	/*transition: -webkit-transform 0.2s ease-out;
	-webkit-transform: translate3d(0, 0px, 0px);*/
}

.menu1 {
	top: 49px;

	/*transition: -webkit-transform 0.2s ease-out;
	-webkit-transform: translate3d(0, 0px, 0px);*/
}

.menu2 {
	top: 98px;
	/*transition: -webkit-transform 0.2s ease-out;
	-webkit-transform: translate3d(0, 0px, 0px);*/
}

.menu3 {
	top: 147px;
	/*transition: -webkit-transform 0.2s ease-out;
	-webkit-transform: translate3d(0, 0px, 0px);*/
	/*-webkit-transition:top 1s linear 2s;*/
}

.menuTransision {
	z-index: 999;
	transition-property: top 0.5s ease 0s;
	/* Firefox 4 */
	-moz-transition: top 0.5s ease 0s;
	/* Safari and Chrome */
	-webkit-transition: top 0.5s ease 0s;
	/* Opera */
	-o-transition: top 0.5s ease 0s;
}

.menu_text {
	height: 48px;
	line-height: 48px;
	margin-left: 25px;
}

.img_arrow_right {
	width: 45px;
	float: right;
	margin-top: 12px;
	margin-right: 25px;
}

.bottom {
	width: 90%;
	margin-left: 5%;
	margin-right: 5%;
	margin-top: 30px;
	color: #929393;
	font-size: 14px;
	line-height: 23px;
	/*position: absolute;
	top:196px;*/
}
</style>
</head>
<script type="text/javascript">
/* 	document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
		WeixinJSBridge.call('hideOptionMenu');
	});	 */
</script>
<body id="myBody" style="display: none; -webkit-user-select: none;">

	<input id="hidden-memberId" type="hidden"
		value="00bd2e9abb4c46a298eb6b2962dbaf3a" />
	<input id="openId" value="ouz52jiY7gfJd3vK-9K6T9mBRPuo" type="hidden" />
	<input id="hidden-checkVersion" type="hidden" value="true" />
	<input id="hidden-isWeight" type="hidden" value="false" />

	<div id="scroolMenu" class="top"></div>
	<div class="bottom">提示：点击按钮，可以设置菜单是否在首页显示。还可以任意拖动菜单上下顺序来改变其在首页上显示的顺序。</div>


	<script type="text/javascript">
		//多少个菜单
		var jsonLen;		
		
		var menus = new Array();
		//创建拖动组件
		function Drag(domId,lineH,json){

			var dom = document.getElementById(domId);
			dom.style.height = (lineH + 1) * json.length + "px";

			renderDrag(dom,lineH,json);

			bindEventDrag(dom);
		}

		//  渲染滑动dom  divId  行高  数据
		function renderDrag(dom,lineH,json){
			
			var html = "";

			for(var i = 0; i < json.length; i++){
				
				html += '<div id="menu' + i + '" class="line" style="top:' + (json[i].sequence - 1) * (lineH + 1) + 'px">';
				
				if(json[i].open == 0){
					
					html += '<img class="img_arrow_right" id="menu_img' + i + '" ontouchstart="clickLockImg(' + i + ')" src="/weixin/v1/img/match_lock.png" />';	
						
				}else{
					
					html += '<img class="img_arrow_right" id="menu_img' + i + '" ontouchstart="clickLockImg(' + i + ')" src="/weixin/v1/img/match_unlock.png" />';
				}			
				
				html += '<div class="menu_text" id="menu_text' + i + '">' + json[i].name + '</div>'
					+'<input type="hidden" id="meun_open' + i + '" value="' + json[i].open + '"/>'
					+'<input type="hidden" id="meun_sequence' + i + '" value="' + json[i].sequence + '"/>'
					+'<input type="hidden" id="menu_id' + i + '" value="' + json[i].id + '"/>'
					+'</div>';

				menus[i] = "menu" + i; 
			}
			dom.innerHTML = html;
		}
		//给dom绑定touch事件
		function bindEventDrag(_dom){
			_dom.addEventListener('touchstart',menuTouchStart,false);
			_dom.addEventListener('touchmove',menuTouchMove,false);
			_dom.addEventListener('touchend',menuTouchEnd,false);
			_dom.addEventListener('touchcancel',menuTouchCancel,false);
		}

		window.onload = function(){
			wxcheckWXSignature();
			ajaxLoadData();
			document.getElementById("myBody").style.display = "block";
			
		};

		//滑动菜单数组
		
		//开始位置、结束位置、当前菜单实际的结束位置
		var startY,endY,endMenuY;
		//判断是否选中
		var isTouch = false;
		//选中的菜单
		var selectMenu;
		var selectMenuIndex;
		var changeMenuIndex;
		//记录触摸时间
		var startTime;
		//记录上滑 、 下滑
		var upOrDown;
		//手指放到屏幕
		function menuTouchStart(event){
			event.preventDefault();
// 			alert("start");
			var menu0 = document.getElementById(menus[0]);
			var menu1 = document.getElementById(menus[1]);
			var menu2 = document.getElementById(menus[2]);
			var menu3 = document.getElementById(menus[3]);	
			var touch = event.touches[0];
			console.log("交换前1:" + menus[0] + "---2:" + menus[1] + "---3:" + menus[2] + "---4:" + menus[3]);
			// startx = touch.pageX;
			startY = touch.clientY;
			startTime = new Date() * 1;
			// console.log("startY:" + startY)
			if(startY < 1 * 49){
				selectMenu = menu0;
				selectMenuIndex = 0;
				
			}else if(startY < 2 * 49){

				selectMenu = menu1;
				selectMenuIndex = 1;
			}else if(startY < 3 * 49){

				selectMenu = menu2;
				selectMenuIndex = 2;

			}else if(startY < 4 * 49){ 
				selectMenu = menu3;
				selectMenuIndex = 3;

			}
			//console.log(selectMenu.id + "----------------selectMenu" +"----selectMenuIndex:" + selectMenuIndex);
			selectMenu.style.background = "#e5e5e5";
			selectMenu.style.zIndex = 999;
		}
		//屏幕移动  主要操作
		function menuTouchMove(event){
			event.preventDefault();
// 			alert("move");
			isTouch = true;//选中
			var touch = event.touches[0];
			//手指Y轴的位置
			var moveY = touch.clientY;
			endY = moveY;
			//滑动位置
			var result = moveY - startY;
			upOrDown = result > 0 ? false : true;	

			for(var i = 0; i < menus.length; i++){
				if(i != selectMenuIndex){
					document.getElementById("menu"+i).style.zIndex = 888;	
				}				
			}

			//为了更自然需要减去开始的手指位置位于当前块的位置
			var moreNumber = startY % 49;
			//菜单的实际位置
			var menuTop = moveY - moreNumber ;
			endMenuY = menuTop;
			console.log("---menuTop:" + menuTop + "---endMenuY:" + endMenuY + "---moveY:" + moveY);
			// endMenuY = moveY;
			selectMenu.style.zIndex = 999;
			selectMenu.style.webkitTransition = 'none';
			selectMenu.style.top = menuTop + "px";
			
				if(moveY > 0 && moveY < 49 * jsonLen){
					console.log( 49 * jsonLen + "---------")
					//下滑
					switch(selectMenuIndex){
						case 0:
	
							if(menuTop < -1 * 49 - 49 / 2){
								//少于0的时候不处理其他菜单
								
							}else if(menuTop < 1 * 49){
								
								document.getElementById(menus[1]) && (document.getElementById(menus[1]).style.top = (49 - result ) + "px");
	
							}else if(menuTop < 2 * 49){
								
								document.getElementById(menus[2]) && (document.getElementById(menus[2]).style.top = ( 49 * 3 - result ) + "px");
	
							}else if(menuTop < 3 * 49){
								
								document.getElementById(menus[3]) && (document.getElementById(menus[3]).style.top = (49 * 5 - result ) + "px");
	
							}else if(menuTop > 5 * 49){
								
							}
							break;
	
						case 1:
							if(menuTop < -1 * 49){
	
								
							}else if(menuTop < 1 * 49){
								
								document.getElementById(menus[0]) && (document.getElementById(menus[0]).style.top = ( 49 - menuTop ) + "px");
	
							}else if(menuTop < 2 * 49){
								
								document.getElementById(menus[2]) && (document.getElementById(menus[2]).style.top = ( 49 * 2 - result ) + "px");
	
							}else if(menuTop < 3 * 49){
								
								document.getElementById(menus[3]) && (document.getElementById(menus[3]).style.top = (49 * 4 - result ) + "px");
	
							}else if(menuTop > 5 * 49){
								
								
							}
	
							break;
						case 2:
							if(menuTop < -1 * 49){
								
								
							}else if(menuTop < 1 * 49){
								
								document.getElementById(menus[0]) && (document.getElementById(menus[0]).style.top = ( 49 - menuTop ) + "px");
	
							}else if(menuTop < 2 * 49){
								
								document.getElementById(menus[1]) && (document.getElementById(menus[1]).style.top = ( 49 * 1 - result ) + "px");
	
							}else if(menuTop < 3 * 49){
								
								document.getElementById(menus[3]) && (document.getElementById(menus[3]).style.top = (49 * 3 - result ) + "px");
	
							}else if(menuTop > 5 * 49){
							
								
							}
	
							break;
						case 3:
	
							if(menuTop < -1 * 49){
								
								
							}else if(menuTop < 1 * 49){
								
								document.getElementById(menus[0]) && (document.getElementById(menus[0]).style.top = ( 49 - menuTop ) + "px");
	
							}else if(menuTop < 2 * 49){
								
								document.getElementById(menus[1]) && (document.getElementById(menus[1]).style.top = ( 49 * 0 - result ) + "px");
	
							}else if(menuTop < 3 * 49){
								
								document.getElementById(menus[2]) && (document.getElementById(menus[2]).style.top = ( 49 * 2 - result ) + "px");							
	
	
							}else if(menuTop > 5 * 49 + 49 / 2){
								//结束后将所有菜单过度到应该所在的位置 / //结束后重置所谓块级元素的位置
							}
	
							break;
					}
				}else{
					
					for(var i = 0; i < menus.length; i++){
							var menu = document.getElementById(menus[i]);
							if(menu){
								menu.style.zIndex = 888;
								menu.style.top = i * 49 + "px";
								menu.style.background = "#fff";
								menu.style.webkitTransition = "all 0.5s ease 0s";		
							}
						}
				}
			
		}

		//离开屏幕触发
		function menuTouchEnd(event){
			event.preventDefault();
			//手指Y轴的位置
// 			alert("end");
			//记录滑动的时间 用于处理快慢操作
			var endTime = new Date() * 1;

			// console.log("endY:" + endY);
			
			if(endTime - startTime > 300){
				//慢操作
				console.log("endMenuY:" + endMenuY);
// 				if(upOrDown){
					//上滑
// 					alert("进入上滑" + "selectMenuIndex:" + selectMenuIndex + "---changeMenuIndex:" + changeMenuIndex);
// 					console.log("endMenuY:" + endMenuY);
					if(endY > 0 && endY < 49 * jsonLen){
							if(endMenuY < -1 * 49){
								//超出最上层边界回到最开始的位置
								changeMenuIndex = selectMenuIndex;
		// 	 					console.log("最上层边界" + "selectMenuIndex:" + selectMenuIndex + "---changeMenuIndex:" + changeMenuIndex);
							}else 
							if(endMenuY < 0 * 49 + 49 / 2){
								//位置0
								changeMenuIndex = 0;
								
							}else if(endMenuY < 1 * 49 + 49 / 2){
								//位置1
								changeMenuIndex = 1;

							}else if(endMenuY < 2 * 49 + 49 / 2){
								//位置2
								changeMenuIndex = 2;

							}else if(endMenuY < 3 * 49 + 49 / 2){
								//位置3
								changeMenuIndex = 3;

							}else{
								//超出最下层边界
								changeMenuIndex = selectMenuIndex;
		// 						console.log("最下层边界" + "selectMenuIndex:" + selectMenuIndex + "---changeMenuIndex:" + changeMenuIndex);
							}
					}else{
						changeMenuIndex = selectMenuIndex;
					}

		
				// console.log("进入下滑" + "selectMenuIndex:" + selectMenuIndex + "---changeMenuIndex:" + changeMenuIndex);
				var temp = menus[changeMenuIndex];
				menus[changeMenuIndex] = menus[selectMenuIndex];
				menus[selectMenuIndex] = temp;

				// console.log("更换后1:" + menus[0] + "---2:" + menus[1] + "---3:" + menus[2] + "---4:" + menus[3]);
				if(selectMenuIndex >= 0 && changeMenuIndex >= 0 && selectMenuIndex != changeMenuIndex){
// 					updateMenusIndex();
					checkChange++;
// 					console.log("checkChange*****************"+ checkChange++);
				}
				


			}else{
				//快操作

				
			}
		
			//结束后将所有菜单过度到应该所在的位置
			for(var i = 0; i < menus.length; i++){
				var menu = document.getElementById(menus[i]);
				if(menu){
					if(i == selectMenuIndex || i == changeMenuIndex){
						menu.style.zIndex = 999;
					}
					menu.style.top = i * 49 + "px";
					menu.style.webkitTransition = "all 0.5s ease 0s";	
				}
				
			}



			//结束后重置所谓块级元素的位置
			for(var i = 0; i < menus.length; i++){
				var menu = document.getElementById(menus[i]);
				if(menu){
					menu.style.zIndex = 888;
					var menuId = menu.id;
					var menuIndex =  menuId.substring(menuId.length - 1,menuId.length);
					document.getElementById("meun_sequence" + menuIndex).value = i + 1;	
				}
				
				
			}
			selectMenu && (selectMenu.style.background = "#fff");
			// console.log("修改之前：---------" + "selectMenuIndex:" + selectMenuIndex + "---changeMenuIndex:" + changeMenuIndex);
			

		}

		function menuTouchCancel(event){
		
			//结束后将所有菜单过度到应该所在的位置 / //结束后重置所谓块级元素的位置
			for(var i = 0; i < menus.length; i++){
				var menu = document.getElementById(menus[i]);
				if(menu){
					menu.style.zIndex = 888;
					menu.style.top = i * 49 + "px";
					menu.style.background = "#fff";
					menu.style.webkitTransition = "all 0.5s ease 0s";	
				}
			}
			
		}
					
	      
		
	</script>

	<!-- 隐藏微信右上角菜单 -->




	<script type="text/javascript"
		src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
	<script type="text/javascript"
		src="{{ URL::asset('weixin/v1/js/weixin_signature_api.js') }}"></script>
</body>
<script type="text/javascript">

var ctx = "";

	//加载数据
	function ajaxLoadData(){
		var memberId = document.getElementById("hidden-memberId").value;
		var xhr = createXmlHttpRequest();
		xhr.onreadystatechange = function() {
			if (xhr.readyState == 4) {
				if (xhr.status == 200) {
					var json = xhr.responseText;
					// console.log(json);
					var jsonData = eval("(" + json + ")");//转换后的JSON对象
					jsonLen = jsonData.length;
					
					Drag('scroolMenu',48,jsonData);
				}
			}
		}
		var url = "/api/ajax/getSwitch";
		xhr.open("post",url + "?memberId=" + memberId + "&type=query&clear=" + new Date() * 1, true);
		xhr.send();
	}

	//初始化数据
	function initData(json){
		var menu = document.getElementById("scroolMenu");
		var checkVersion = document.getElementById("hidden-checkVersion").value;
		var isWeight = document.getElementById("hidden-isWeight").value;
// 		console.log("--------checkVersion:" + checkVersion);
		var html = "";

		for(var i = 0; i < json.length; i++){
			if(checkVersion =="false" && json[i].name == "睡眠"){
// 				console.log("gggggggggggggg")
				html += '<div id="menu' + i + '" class="line" style="top:' + (json[i].sequence - 1) * 49 + 'px;color:rgb(188,188,188);">';
				
				html += '<img class="img_arrow_right" id="menu_img' + i + '" src="/weixin/v1/img/match_lock.png" />';
			
			}else if(isWeight == "false" && json[i].name == "体重"){
				
				html += '<div id="menu' + i + '" class="line" style="top:' + (json[i].sequence - 1) * 49 + 'px;color:rgb(188,188,188);">';
				
				html += '<img class="img_arrow_right" id="menu_img' + i + '" src="/weixin/v1/img/match_lock.png" />';
				
			}else{
				
				html += '<div id="menu' + i + '" class="line" style="top:' + (json[i].sequence - 1) * 49 + 'px">';
				
				if(json[i].open == 0){
					
					html += '<img class="img_arrow_right" id="menu_img' + i + '" ontouchstart="clickLockImg(' + i + ')" src="/weixin/v1/img/match_lock.png" />';	
						
				}else{
					
					html += '<img class="img_arrow_right" id="menu_img' + i + '" ontouchstart="clickLockImg(' + i + ')" src="/weixin/v1/img/match_unlock.png" />';
				}			
			}
			html += '<div class="menu_text" id="menu_text' + i + '">' + json[i].name + '</div>'
				+'<input type="hidden" id="meun_open' + i + '" value="' + json[i].open + '"/>'
				+'<input type="hidden" id="meun_sequence' + i + '" value="' + json[i].sequence + '"/>'
				+'<input type="hidden" id="menu_id' + i + '" value="' + json[i].id + '"/>'
				+'</div>';

			menus[i] = "menu" + i; 
		}
		menu.innerHTML = html;

		document.getElementById("myBody").style.display = "block";

	}

	//切换按钮的显示状态
	function clickLockImg(index){
		var open = document.getElementById("meun_open" + index).value;
		// console.log("open:" + open);
		if(open == 0){

			document.getElementById("menu_img" + index).src = "/weixin/v1/img/match_unlock.png";
			// console.log("切换显示");
			open = 1;	
			document.getElementById("meun_open" + index).value = open;

		}else{

			document.getElementById("menu_img" + index).src = "/weixin/v1/img/match_lock.png";
			// console.log("切换隐藏");
			open = 0;
			document.getElementById("meun_open" + index).value = open;

		}
		checkChange++;
// 		updateMenuIsOpen(open,index);
	}




	//初始化图片
	function init(json){
		if(json.data.length >0){
			
			for (var i = 0; i < json.data.length; i++) {
				var data = json.data[i];
				
				document.getElementById("meun_open"+data.open).value=data.open;
				document.getElementById("meun_sequence"+data.sequence).value=data.sequence;
				
				document.getElementById("menu_text"+data.sequence).innerHTML = data.name;
				if(data.open == 1){
					document.getElementById("menu_img"+data.sequence).src=ctx+"/v3/img/match_lock.png";
				}else{
					document.getElementById("menu_img"+data.sequence).src=ctx+"/v3/img/match_unlock.png";
				}
			}
		
	}
	}


	window.addEventListener("pagehide", function(){
	    updateMenusIndex2();//Ajax请求 
	    setTimeout(function(){},1000); 
	}, false);




	var checkChange = 0;
	//更新菜单的位置以及状态
	function updateMenusIndex2(){
		var memberId = document.getElementById("hidden-memberId").value;
		var ids = "";
		var opens = "";
		var indexs = "";
		
		if(checkChange > 0){
			for(var i = 0; i < menus.length; i++){
				var menuId = document.getElementById(menus[i]).id;
				var idNo = menuId.substring(menuId.length - 1, menuId.length);
				ids += document.getElementById("menu_id" + idNo).value + ","; 
				opens += document.getElementById("meun_open" + idNo).value + ",";
				indexs += (i + 1) + ",";
			}
			
		}
		var xhr = createXmlHttpRequest();
		var url = ctx + "/wechat/ajax_function";
		xhr.open("post",url + "?memberId=" + memberId + "&ids="+ ids + "&opens=" + opens + "&indexs=" + indexs + "&type=update&clear=" + new Date() * 1, false);
		xhr.send();
	}
	
</script>
</html>